<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>GSoC2011SfM: D:/Travail/These/Determination caracteristiques camera/GSoC/SfM/src/TracksOfPoints.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">GSoC2011SfM
   &#160;<span id="projectnumber">0.1</span>
   </div>
   <div id="projectbrief">Google Summer of Code 2011: Structure from motion</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">D:/Travail/These/Determination caracteristiques camera/GSoC/SfM/src/TracksOfPoints.cpp</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00002"></a>00002 <span class="preprocessor">#include &quot;TracksOfPoints.h&quot;</span>
<a name="l00003"></a>00003 
<a name="l00004"></a>00004 <span class="preprocessor">#include &quot;PointsToTrack.h&quot;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &quot;PointOfView.h&quot;</span>
<a name="l00006"></a>00006 <span class="preprocessor">#include &quot;Camera.h&quot;</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="keyword">namespace </span>OpencvSfM{
<a name="l00009"></a>00009   <span class="keyword">using</span> cv::KeyPoint;
<a name="l00010"></a>00010   <span class="keyword">using</span> std::vector;
<a name="l00011"></a>00011   <span class="keyword">using</span> cv::Point3d;
<a name="l00012"></a>00012   <span class="keyword">using</span> cv::DMatch;
<a name="l00013"></a>00013   <span class="keyword">using</span> cv::Ptr;
<a name="l00014"></a>00014   <span class="keyword">using</span> cv::Mat;
<a name="l00015"></a>00015 
<a name="l00016"></a>00016   <span class="keyword">inline</span> <span class="keywordtype">void</span> quickSort( vector&lt;ImageLink&gt;&amp; outLinks,
<a name="l00017"></a>00017     vector&lt;int&gt;&amp; arr, <span class="keywordtype">int</span> left, <span class="keywordtype">int</span> right ) {
<a name="l00018"></a>00018       <span class="keywordtype">int</span> i = left, j = right;
<a name="l00019"></a>00019       <span class="keywordtype">int</span> tmp;
<a name="l00020"></a>00020       <span class="keywordtype">int</span> pivot = arr[ ( left + right ) / 2 ];
<a name="l00021"></a>00021 
<a name="l00022"></a>00022       <span class="comment">/* partition */</span>
<a name="l00023"></a>00023       <span class="keywordflow">while</span> ( i &lt;= j ) {
<a name="l00024"></a>00024         <span class="keywordflow">while</span> ( arr[ i ] &lt; pivot )
<a name="l00025"></a>00025           i++;
<a name="l00026"></a>00026         <span class="keywordflow">while</span> ( arr[ j ] &gt; pivot )
<a name="l00027"></a>00027           j--;
<a name="l00028"></a>00028         <span class="keywordflow">if</span> ( i &lt; j ) {
<a name="l00029"></a>00029           tmp = arr[ i ];
<a name="l00030"></a>00030           arr[ i ] = arr[ j ];
<a name="l00031"></a>00031           arr[ j ] = tmp;
<a name="l00032"></a>00032 
<a name="l00033"></a>00033           ImageLink tmp1 = outLinks[ i ];
<a name="l00034"></a>00034           outLinks[ i ] = outLinks[ j ];
<a name="l00035"></a>00035           outLinks[ j ] = tmp1;
<a name="l00036"></a>00036 
<a name="l00037"></a>00037         }
<a name="l00038"></a>00038         <span class="keywordflow">if</span> ( i &lt;= j ) {
<a name="l00039"></a>00039           i++;
<a name="l00040"></a>00040           j--;
<a name="l00041"></a>00041         }
<a name="l00042"></a>00042       };
<a name="l00043"></a>00043 
<a name="l00044"></a>00044       <span class="comment">/* recursion */</span>
<a name="l00045"></a>00045       <span class="keywordflow">if</span> ( left &lt; j )
<a name="l00046"></a>00046         quickSort( outLinks, arr, left, j );
<a name="l00047"></a>00047       <span class="keywordflow">if</span> ( i &lt; right )
<a name="l00048"></a>00048         quickSort( outLinks, arr, i, right );
<a name="l00049"></a>00049   }
<a name="l00050"></a>00050 
<a name="l00051"></a>00051   TrackOfPoints::~TrackOfPoints()
<a name="l00052"></a>00052   {
<a name="l00053"></a>00053     <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a>.release();
<a name="l00054"></a>00054   }
<a name="l00055"></a>00055 
<a name="l00056"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a83543ac9e156336f5ec070d2963f185c">00056</a>   <span class="keywordtype">bool</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a83543ac9e156336f5ec070d2963f185c">TrackOfPoints::addMatch</a>( <span class="keyword">const</span> <span class="keywordtype">int</span> image_src, <span class="keyword">const</span> <span class="keywordtype">int</span> point_idx1 )
<a name="l00057"></a>00057   {
<a name="l00058"></a>00058     <span class="keywordflow">if</span>( <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ada7b5f6522454fe0a57438396e3ef24c">track_consistance</a>&lt;0 )
<a name="l00059"></a>00059     {<span class="comment">//add to track to remember us about this problem....</span>
<a name="l00060"></a>00060       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.push_back( image_src );
<a name="l00061"></a>00061       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>.push_back( point_idx1 );
<a name="l00062"></a>00062       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a>.push_back(<span class="keyword">false</span>);
<a name="l00063"></a>00063       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00064"></a>00064     }
<a name="l00065"></a>00065     <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a>.push_back(<span class="keyword">true</span>);
<a name="l00066"></a>00066 
<a name="l00067"></a>00067     <span class="comment">//If a track contains more than one keypoint in the same image but</span>
<a name="l00068"></a>00068     <span class="comment">//a different keypoint, it is deemed inconsistent.</span>
<a name="l00069"></a>00069     vector&lt;unsigned int&gt;::iterator indexImg = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.begin( );
<a name="l00070"></a>00070     vector&lt;unsigned int&gt;::iterator end_iter = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.end( );
<a name="l00071"></a>00071     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index=0;
<a name="l00072"></a>00072     <span class="keywordflow">while</span>( indexImg != end_iter )
<a name="l00073"></a>00073     {
<a name="l00074"></a>00074       <span class="keywordflow">if</span> ( *indexImg == image_src )
<a name="l00075"></a>00075       {
<a name="l00076"></a>00076         <span class="keywordflow">if</span>( <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ index ] == point_idx1 )
<a name="l00077"></a>00077         {
<a name="l00078"></a>00078           <span class="keywordflow">if</span>( <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ada7b5f6522454fe0a57438396e3ef24c">track_consistance</a>&gt;=0 )
<a name="l00079"></a>00079             <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ada7b5f6522454fe0a57438396e3ef24c">track_consistance</a>++;
<a name="l00080"></a>00080         }
<a name="l00081"></a>00081         <span class="keywordflow">else</span>
<a name="l00082"></a>00082           <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ada7b5f6522454fe0a57438396e3ef24c">track_consistance</a>=-1;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084         <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ada7b5f6522454fe0a57438396e3ef24c">track_consistance</a>&gt;=0;
<a name="l00085"></a>00085       }
<a name="l00086"></a>00086       index++;
<a name="l00087"></a>00087       indexImg++;
<a name="l00088"></a>00088     }
<a name="l00089"></a>00089 
<a name="l00090"></a>00090     <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.push_back( image_src );
<a name="l00091"></a>00091     <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>.push_back( point_idx1 );
<a name="l00092"></a>00092     <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ada7b5f6522454fe0a57438396e3ef24c">track_consistance</a>&gt;=0;
<a name="l00093"></a>00093   }
<a name="l00094"></a>00094 
<a name="l00095"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ac8a9ed8a3334e43833a5e14e79689390">00095</a>   <span class="keywordtype">bool</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ac8a9ed8a3334e43833a5e14e79689390">TrackOfPoints::containPoint</a>( <span class="keyword">const</span> <span class="keywordtype">int</span> image_src,
<a name="l00096"></a>00096     <span class="keyword">const</span> <span class="keywordtype">int</span> point_idx1 )<span class="keyword"> const</span>
<a name="l00097"></a>00097 <span class="keyword">  </span>{
<a name="l00098"></a>00098     <span class="comment">//we don&#39;t use find here because we want the number instead of iterator...</span>
<a name="l00099"></a>00099     vector&lt;unsigned int&gt;::const_iterator indexImg = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.begin( );
<a name="l00100"></a>00100     vector&lt;unsigned int&gt;::const_iterator end_iter = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.end( );
<a name="l00101"></a>00101     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index=0;
<a name="l00102"></a>00102     <span class="keywordflow">while</span>( indexImg != end_iter )
<a name="l00103"></a>00103     {
<a name="l00104"></a>00104       <span class="keywordflow">if</span> ( *indexImg == image_src )
<a name="l00105"></a>00105       {
<a name="l00106"></a>00106         <span class="keywordflow">if</span>( <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ index ] == point_idx1 )
<a name="l00107"></a>00107           <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a>[ index ];
<a name="l00108"></a>00108       }
<a name="l00109"></a>00109       index++;
<a name="l00110"></a>00110       indexImg++;
<a name="l00111"></a>00111     }
<a name="l00112"></a>00112     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00113"></a>00113   }
<a name="l00114"></a>00114 
<a name="l00115"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a8d15153ed498789f27c319dadd6c58fd">00115</a>   DMatch <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a8d15153ed498789f27c319dadd6c58fd">TrackOfPoints::toDMatch</a>( <span class="keyword">const</span> <span class="keywordtype">int</span> img1,<span class="keyword">const</span> <span class="keywordtype">int</span> img2 )<span class="keyword"> const</span>
<a name="l00116"></a>00116 <span class="keyword">  </span>{
<a name="l00117"></a>00117     DMatch outMatch;
<a name="l00118"></a>00118     <span class="keywordtype">char</span> nbFound=0;
<a name="l00119"></a>00119     <span class="comment">//we don&#39;t use find here because we want the number instead of iterator...</span>
<a name="l00120"></a>00120     vector&lt;unsigned int&gt;::const_iterator indexImg = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.begin( );
<a name="l00121"></a>00121     vector&lt;unsigned int&gt;::const_iterator end_iter = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.end( );
<a name="l00122"></a>00122     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index=0;
<a name="l00123"></a>00123     <span class="keywordflow">while</span>( indexImg != end_iter )
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125       <span class="keywordflow">if</span> ( *indexImg == img1 )
<a name="l00126"></a>00126       {
<a name="l00127"></a>00127         nbFound++;
<a name="l00128"></a>00128         outMatch.trainIdx = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ index ];
<a name="l00129"></a>00129         <span class="keywordflow">if</span>( nbFound==2 )
<a name="l00130"></a>00130           <span class="keywordflow">return</span> outMatch;
<a name="l00131"></a>00131       }
<a name="l00132"></a>00132       <span class="keywordflow">if</span> ( *indexImg == img2 )
<a name="l00133"></a>00133       {
<a name="l00134"></a>00134         nbFound++;
<a name="l00135"></a>00135         outMatch.queryIdx = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ index ];
<a name="l00136"></a>00136         <span class="keywordflow">if</span>( nbFound==2 )
<a name="l00137"></a>00137           <span class="keywordflow">return</span> outMatch;
<a name="l00138"></a>00138       }
<a name="l00139"></a>00139       index++;
<a name="l00140"></a>00140       indexImg++;
<a name="l00141"></a>00141     }
<a name="l00142"></a>00142     <span class="keywordflow">return</span> outMatch;
<a name="l00143"></a>00143   };
<a name="l00144"></a>00144 
<a name="l00145"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a8bca030b779db3f434c29cdf6ad155db">00145</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a8bca030b779db3f434c29cdf6ad155db">TrackOfPoints::getMatch</a>( <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> index,
<a name="l00146"></a>00146     <span class="keywordtype">int</span> &amp;idImage, <span class="keywordtype">int</span> &amp;idPoint )<span class="keyword"> const</span>
<a name="l00147"></a>00147 <span class="keyword">  </span>{
<a name="l00148"></a>00148     <span class="keywordtype">char</span> nbFound=0;
<a name="l00149"></a>00149     <span class="keywordflow">if</span>( index &lt; <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( ) )
<a name="l00150"></a>00150     {
<a name="l00151"></a>00151       idImage = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>[ index ];
<a name="l00152"></a>00152       idPoint = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ index ];
<a name="l00153"></a>00153     }
<a name="l00154"></a>00154   };
<a name="l00155"></a>00155 
<a name="l00156"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad356faa6559c985755242642b50f3145">00156</a>   <span class="keywordtype">double</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad356faa6559c985755242642b50f3145">TrackOfPoints::errorEstimate</a>( std::vector&lt;PointOfView&gt;&amp; cameras,
<a name="l00157"></a>00157     <span class="keyword">const</span> std::vector&lt; cv::Ptr&lt; PointsToTrack &gt; &gt; &amp;points_to_track,
<a name="l00158"></a>00158     cv::Vec3d&amp; points3D, <span class="keyword">const</span> std::vector&lt;bool&gt; &amp;masks)<span class="keyword"> const</span>
<a name="l00159"></a>00159 <span class="keyword">  </span>{
<a name="l00160"></a>00160     <span class="keywordtype">double</span> distance=0.0;
<a name="l00161"></a>00161     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nviews = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( );
<a name="l00162"></a>00162     <span class="keywordtype">double</span> real_views = 0.0;
<a name="l00163"></a>00163     <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cpt = 0; cpt &lt; nviews; cpt++ ) {
<a name="l00164"></a>00164       <span class="keywordtype">int</span> num_camera=<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>[ cpt ];
<a name="l00165"></a>00165       <span class="keywordtype">int</span> num_point=<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ cpt ];
<a name="l00166"></a>00166       <span class="keywordflow">if</span>(( masks.size() == 0 ) || ( cpt&lt;masks.size() &amp;&amp; masks[cpt] ))
<a name="l00167"></a>00167       {
<a name="l00168"></a>00168         cv::Ptr&lt;PointsToTrack&gt; points2D = points_to_track[ num_camera ];
<a name="l00169"></a>00169 
<a name="l00170"></a>00170         <span class="keyword">const</span> KeyPoint&amp; p=points2D-&gt;getKeypoint( num_point );
<a name="l00171"></a>00171         cv::Vec2d projP = cameras[ num_camera ].project3DPointIntoImage( points3D );
<a name="l00172"></a>00172 
<a name="l00173"></a>00173         <span class="comment">//compute back-projection</span>
<a name="l00174"></a>00174         distance += sqrt( (p.pt.x-projP[ 0 ] )*( p.pt.x-projP[ 0 ] ) +
<a name="l00175"></a>00175           ( p.pt.y-projP[ 1 ] )*( p.pt.y-projP[ 1 ] ) );
<a name="l00176"></a>00176         real_views++;
<a name="l00177"></a>00177       }
<a name="l00178"></a>00178     }
<a name="l00179"></a>00179     <span class="keywordflow">return</span> distance/real_views;
<a name="l00180"></a>00180   }
<a name="l00181"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a0881b49d483de9be1c7e0b0d3bbcc306">00181</a>   <span class="keywordtype">double</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a0881b49d483de9be1c7e0b0d3bbcc306">TrackOfPoints::triangulateLinear</a>( vector&lt;PointOfView&gt;&amp; cameras,
<a name="l00182"></a>00182     <span class="keyword">const</span> std::vector&lt; cv::Ptr&lt; PointsToTrack &gt; &gt; &amp;points_to_track,
<a name="l00183"></a>00183     cv::Vec3d&amp; points3D, <span class="keyword">const</span> vector&lt;bool&gt; &amp;masks )
<a name="l00184"></a>00184   {
<a name="l00185"></a>00185     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nviews = 0;
<a name="l00186"></a>00186     <span class="keywordtype">bool</span> hasMask=<span class="keyword">false</span>;
<a name="l00187"></a>00187     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;
<a name="l00188"></a>00188     <span class="keywordflow">if</span>( masks.size( )==<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( ) )
<a name="l00189"></a>00189     {
<a name="l00190"></a>00190       <span class="keywordflow">for</span> ( i=0; i&lt;<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( ); ++i )
<a name="l00191"></a>00191       {
<a name="l00192"></a>00192         <span class="keywordflow">if</span>( masks[ i ]!=0 )
<a name="l00193"></a>00193           nviews++;
<a name="l00194"></a>00194       }
<a name="l00195"></a>00195       hasMask=<span class="keyword">true</span>;
<a name="l00196"></a>00196     }<span class="keywordflow">else</span>
<a name="l00197"></a>00197     {
<a name="l00198"></a>00198       nviews = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( );
<a name="l00199"></a>00199     }
<a name="l00200"></a>00200 
<a name="l00201"></a>00201     Mat design = Mat::zeros( 3*nviews, 4 + nviews,CV_64FC1 );
<a name="l00202"></a>00202     <span class="keywordtype">unsigned</span>  <span class="keywordtype">int</span> real_position=0;
<a name="l00203"></a>00203     i = 0;
<a name="l00204"></a>00204     <span class="keywordflow">for</span> ( real_position = 0; real_position &lt; <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( );
<a name="l00205"></a>00205       ++real_position ) {
<a name="l00206"></a>00206         <span class="keywordflow">if</span>( !hasMask || ( hasMask &amp;&amp; masks[ real_position ]!=0 ))
<a name="l00207"></a>00207         {
<a name="l00208"></a>00208           <span class="keywordtype">int</span> num_camera=<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>[ real_position ];
<a name="l00209"></a>00209           <span class="keywordtype">int</span> num_point=<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ real_position ];
<a name="l00210"></a>00210           cv::Ptr&lt;PointsToTrack&gt; points2D = points_to_track[ num_camera ];
<a name="l00211"></a>00211           <span class="keyword">const</span> KeyPoint&amp; p=points2D-&gt;getKeypoint( num_point );
<a name="l00212"></a>00212 
<a name="l00213"></a>00213           design( cv::Range( 3*i,3*i+3 ), cv::Range( 0,4 )) =
<a name="l00214"></a>00214             -cameras[ num_camera ].getProjectionMatrix( );
<a name="l00215"></a>00215           design.at&lt;<span class="keywordtype">double</span>&gt;( 3*i + 0, 4 + i ) = p.pt.x;
<a name="l00216"></a>00216           design.at&lt;<span class="keywordtype">double</span>&gt;( 3*i + 1, 4 + i ) = p.pt.y;
<a name="l00217"></a>00217           design.at&lt;<span class="keywordtype">double</span>&gt;( 3*i + 2, 4 + i ) = 1.0;
<a name="l00218"></a>00218           i++;
<a name="l00219"></a>00219         }
<a name="l00220"></a>00220     }
<a name="l00221"></a>00221     Mat X_and_alphas;
<a name="l00222"></a>00222     cv::SVD::solveZ( design, X_and_alphas );
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     <span class="keywordtype">double</span> scal_factor=X_and_alphas.at&lt;<span class="keywordtype">double</span>&gt;( 3,0 );
<a name="l00225"></a>00225     points3D[ 0 ]=X_and_alphas.at&lt;<span class="keywordtype">double</span>&gt;( 0,0 )/scal_factor;
<a name="l00226"></a>00226     points3D[ 1 ]=X_and_alphas.at&lt;<span class="keywordtype">double</span>&gt;( 1,0 )/scal_factor;
<a name="l00227"></a>00227     points3D[ 2 ]=X_and_alphas.at&lt;<span class="keywordtype">double</span>&gt;( 2,0 )/scal_factor;
<a name="l00228"></a>00228 
<a name="l00229"></a>00229     <span class="comment">//update the point 3D:</span>
<a name="l00230"></a>00230     <span class="keywordflow">if</span>( <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a>.empty( ) )
<a name="l00231"></a>00231       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a> = Ptr&lt;cv::Vec3d&gt;( <span class="keyword">new</span> cv::Vec3d( points3D ) );
<a name="l00232"></a>00232     <span class="keywordflow">else</span>
<a name="l00233"></a>00233       *<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a> = points3D;
<a name="l00234"></a>00234 
<a name="l00235"></a>00235     <span class="keywordflow">return</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad356faa6559c985755242642b50f3145">errorEstimate</a>( cameras, points_to_track, points3D, masks );
<a name="l00236"></a>00236   }
<a name="l00237"></a>00237 
<a name="l00238"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a2b4033102211c324ead8214849a6da93">00238</a>   <span class="keywordtype">double</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a2b4033102211c324ead8214849a6da93">TrackOfPoints::triangulateRobust</a>( std::vector&lt;PointOfView&gt;&amp; cameras,
<a name="l00239"></a>00239     <span class="keyword">const</span> std::vector&lt; cv::Ptr&lt; PointsToTrack &gt; &gt; &amp;points_to_track,
<a name="l00240"></a>00240     cv::Vec3d&amp; points3D, <span class="keywordtype">double</span> reproj_error,
<a name="l00241"></a>00241     <span class="keyword">const</span> std::vector&lt;bool&gt; &amp;masksValues )
<a name="l00242"></a>00242   {
<a name="l00243"></a>00243     cv::RNG&amp; rng = cv::theRNG( );
<a name="l00244"></a>00244     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nviews = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( );
<a name="l00245"></a>00245     <span class="keywordtype">double</span> distance=0, best_distance=1e20;
<a name="l00246"></a>00246     vector&lt;bool&gt; masks;
<a name="l00247"></a>00247     cv::Vec3d bestPoints3D;
<a name="l00248"></a>00248 
<a name="l00249"></a>00249     <span class="keywordtype">int</span> ptSize = 0;
<a name="l00250"></a>00250     <span class="keywordtype">bool</span> has_mask = masksValues.size( ) == nviews;
<a name="l00251"></a>00251     <span class="keywordflow">if</span>( has_mask )
<a name="l00252"></a>00252     {
<a name="l00253"></a>00253       <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;nviews; ++i )
<a name="l00254"></a>00254       {
<a name="l00255"></a>00255         <span class="keywordflow">if</span>( masksValues[ i ]!=0 )
<a name="l00256"></a>00256           ptSize++;
<a name="l00257"></a>00257       }
<a name="l00258"></a>00258     }
<a name="l00259"></a>00259     <span class="keywordflow">else</span>
<a name="l00260"></a>00260       ptSize = nviews;
<a name="l00261"></a>00261 
<a name="l00262"></a>00262     <span class="keywordtype">int</span> num_iter=0, max_iter=ptSize - 1;
<a name="l00263"></a>00263     <span class="keywordflow">for</span>( num_iter=0; num_iter&lt;max_iter; ++num_iter )
<a name="l00264"></a>00264     {
<a name="l00265"></a>00265       masks.clear( );
<a name="l00266"></a>00266       <span class="keywordtype">int</span> nb_vals=0;
<a name="l00267"></a>00267       <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cpt = 0; cpt &lt; nviews; cpt++ ) {
<a name="l00268"></a>00268         <span class="keywordtype">bool</span> valTmp = ( rng( 2 ) != 0 );
<a name="l00269"></a>00269         <span class="keywordflow">if</span>( has_mask )
<a name="l00270"></a>00270           valTmp = valTmp &amp; masksValues[ cpt ];
<a name="l00271"></a>00271         <span class="keywordflow">if</span>( valTmp )
<a name="l00272"></a>00272           nb_vals++;
<a name="l00273"></a>00273         masks.push_back( valTmp );
<a name="l00274"></a>00274       }
<a name="l00275"></a>00275       <span class="keywordflow">while</span>( nb_vals&lt;2 )
<a name="l00276"></a>00276       {
<a name="l00277"></a>00277         <span class="keywordtype">int</span> valTmp = rng( nviews );
<a name="l00278"></a>00278         <span class="keywordflow">while</span>( !( masks[ valTmp ] == 0 &amp;&amp;
<a name="l00279"></a>00279           ( !has_mask || masksValues[ valTmp ] ) ) )
<a name="l00280"></a>00280         {
<a name="l00281"></a>00281           valTmp = (valTmp + 1) % nviews;
<a name="l00282"></a>00282         }
<a name="l00283"></a>00283         masks[ valTmp ] = 1;
<a name="l00284"></a>00284         nb_vals++;
<a name="l00285"></a>00285       }
<a name="l00286"></a>00286       <span class="comment">//create mask:</span>
<a name="l00287"></a>00287       distance = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a0881b49d483de9be1c7e0b0d3bbcc306">triangulateLinear</a>( cameras, points_to_track, points3D, masks );
<a name="l00288"></a>00288 
<a name="l00289"></a>00289       <span class="keywordflow">if</span>( distance &lt; best_distance )
<a name="l00290"></a>00290       {
<a name="l00291"></a>00291         <span class="comment">//new best model...</span>
<a name="l00292"></a>00292         bestPoints3D = points3D;
<a name="l00293"></a>00293         best_distance = distance;
<a name="l00294"></a>00294         <span class="keywordflow">if</span>( best_distance&lt;reproj_error )
<a name="l00295"></a>00295           num_iter=nviews;<span class="comment">//quit the loop!</span>
<a name="l00296"></a>00296       }
<a name="l00297"></a>00297     }
<a name="l00298"></a>00298     points3D = bestPoints3D;
<a name="l00299"></a>00299     <span class="comment">//update the point 3D:</span>
<a name="l00300"></a>00300     <span class="keywordflow">if</span>( <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a>.empty( ) )
<a name="l00301"></a>00301       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a> = Ptr&lt;cv::Vec3d&gt;( <span class="keyword">new</span> cv::Vec3d( points3D ) );
<a name="l00302"></a>00302     <span class="keywordflow">else</span>
<a name="l00303"></a>00303       *<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a> = points3D;
<a name="l00304"></a>00304     <span class="keywordflow">return</span> best_distance;
<a name="l00305"></a>00305   }
<a name="l00306"></a>00306 
<a name="l00307"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#aec31d0a12aa5085776a98cea6708ee5e">00307</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#aec31d0a12aa5085776a98cea6708ee5e">TrackOfPoints::removeOutliers</a>( std::vector&lt;PointOfView&gt;&amp; cameras,
<a name="l00308"></a>00308     <span class="keyword">const</span> std::vector&lt; cv::Ptr&lt; PointsToTrack &gt; &gt; &amp;points_to_track,
<a name="l00309"></a>00309     <span class="keywordtype">double</span> reproj_error, std::vector&lt;bool&gt; *masksValues )
<a name="l00310"></a>00310   {
<a name="l00311"></a>00311     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nviews = <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size( );
<a name="l00312"></a>00312 
<a name="l00313"></a>00313     <span class="keywordtype">int</span> ptSize = 0;
<a name="l00314"></a>00314     <span class="keywordflow">if</span>(masksValues == NULL)
<a name="l00315"></a>00315       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a>.assign(nviews , <span class="keyword">true</span>);
<a name="l00316"></a>00316     <span class="keywordflow">else</span>
<a name="l00317"></a>00317       <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a> = *masksValues;
<a name="l00318"></a>00318 
<a name="l00319"></a>00319     <span class="keywordtype">int</span> nb_vals=0;
<a name="l00320"></a>00320     <span class="keywordflow">for</span> ( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cpt = 0; cpt &lt; nviews; cpt++ ) {
<a name="l00321"></a>00321       <span class="keywordflow">if</span>(<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a>[cpt])
<a name="l00322"></a>00322       {
<a name="l00323"></a>00323           <span class="keywordtype">int</span> num_camera=<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>[ cpt ];
<a name="l00324"></a>00324           <span class="keywordtype">int</span> num_point=<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[ cpt ];
<a name="l00325"></a>00325           cv::Ptr&lt;PointsToTrack&gt; points2D = points_to_track[ num_camera ];
<a name="l00326"></a>00326           <span class="keyword">const</span> KeyPoint&amp; p=points2D-&gt;getKeypoint( num_point );
<a name="l00327"></a>00327 
<a name="l00328"></a>00328           <span class="comment">//project 3D point:</span>
<a name="l00329"></a>00329           cv::Vec2d projP = cameras[ num_camera ].project3DPointIntoImage( *<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ad47f8be9467b36497a7484aea438cbcc" title="The corresponding 3D coordinates. If not available, Ptr is empty.">point3D</a> );
<a name="l00330"></a>00330 
<a name="l00331"></a>00331           <span class="comment">//compute error:</span>
<a name="l00332"></a>00332           <span class="keywordtype">double</span> error = sqrt( (p.pt.x-projP[ 0 ] )*( p.pt.x-projP[ 0 ] ) +
<a name="l00333"></a>00333             ( p.pt.y-projP[ 1 ] )*( p.pt.y-projP[ 1 ] ) );
<a name="l00334"></a>00334 
<a name="l00335"></a>00335           <span class="keywordflow">if</span>(error&gt;reproj_error)
<a name="l00336"></a>00336             <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#af55a2dcf8abb42bdb1827e38eee9866b">good_values</a>[cpt] = <span class="keyword">false</span>;
<a name="l00337"></a>00337       }
<a name="l00338"></a>00338     }
<a name="l00339"></a>00339   }
<a name="l00340"></a>00340 
<a name="l00341"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a7ee400c9fbb6a990f9d34a2370ddac95">00341</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a7ee400c9fbb6a990f9d34a2370ddac95">TrackOfPoints::keepTrackHavingImage</a>( <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> idx_image,
<a name="l00342"></a>00342     vector&lt;TrackOfPoints&gt;&amp; tracks )
<a name="l00343"></a>00343   {
<a name="l00344"></a>00344     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cpt = 0,
<a name="l00345"></a>00345       end = tracks.size();
<a name="l00346"></a>00346     <span class="keywordflow">for</span>(cpt = 0; cpt&lt;end-1; ++cpt)
<a name="l00347"></a>00347     {
<a name="l00348"></a>00348       <span class="keywordflow">if</span>( !tracks[cpt].<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#aea06a066b4be5fa2ff5ef09cea7fb745">containImage</a>(idx_image) )
<a name="l00349"></a>00349       {
<a name="l00350"></a>00350         tracks[cpt] = tracks[ end-1 ];
<a name="l00351"></a>00351         end--;tracks.pop_back();
<a name="l00352"></a>00352         cpt--;
<a name="l00353"></a>00353       }
<a name="l00354"></a>00354     }
<a name="l00355"></a>00355     <span class="comment">//last one:</span>
<a name="l00356"></a>00356     <span class="keywordflow">if</span>( !tracks[cpt].<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#aea06a066b4be5fa2ff5ef09cea7fb745">containImage</a>(idx_image) )
<a name="l00357"></a>00357       tracks.pop_back();
<a name="l00358"></a>00358   }
<a name="l00359"></a>00359 
<a name="l00360"></a>00360 
<a name="l00361"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#abe9770a4050b3b9d66e4eab14a7fa5fc">00361</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#abe9770a4050b3b9d66e4eab14a7fa5fc">TrackOfPoints::mixTracks</a>( <span class="keyword">const</span> std::vector&lt;TrackOfPoints&gt;&amp; list_tracks,
<a name="l00362"></a>00362     std::vector&lt;TrackOfPoints&gt;* mixed_tracks )
<a name="l00363"></a>00363   {
<a name="l00364"></a>00364     <span class="comment">//add to mixed_tracks the new tracks from list_tracks who are not in mixed_tracks:</span>
<a name="l00365"></a>00365     vector&lt;TrackOfPoints&gt;::const_iterator track_it = list_tracks.begin( );
<a name="l00366"></a>00366     vector&lt;TrackOfPoints&gt;::const_iterator track_end = list_tracks.end( );
<a name="l00367"></a>00367 
<a name="l00368"></a>00368     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> mixed_size = mixed_tracks-&gt;size();
<a name="l00369"></a>00369 
<a name="l00370"></a>00370     <span class="keywordflow">while</span> ( track_it != track_end )
<a name="l00371"></a>00371     {
<a name="l00372"></a>00372       <span class="keyword">const</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html" title="This class store the track of keypoints. A track is a connected set of matching keypoints across mult...">TrackOfPoints</a>&amp; track = ( *track_it );
<a name="l00373"></a>00373 
<a name="l00374"></a>00374       <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cpt = 0;
<a name="l00375"></a>00375 
<a name="l00376"></a>00376       <span class="keywordtype">bool</span> is_found=<span class="keyword">false</span>;
<a name="l00377"></a>00377       <span class="keywordflow">while</span> ( cpt&lt;mixed_size &amp;&amp; !is_found )
<a name="l00378"></a>00378       {
<a name="l00379"></a>00379         <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html" title="This class store the track of keypoints. A track is a connected set of matching keypoints across mult...">TrackOfPoints</a>&amp; track1 = (*mixed_tracks)[ cpt ];
<a name="l00380"></a>00380         <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i&lt;track1.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size()&amp;&amp;!is_found; ++i)
<a name="l00381"></a>00381         {
<a name="l00382"></a>00382           <span class="keywordflow">if</span>( track.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#ac8a9ed8a3334e43833a5e14e79689390">containPoint</a>( track1.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>[i],
<a name="l00383"></a>00383             track1.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[i]) )<span class="comment">//the same keypoint is found!</span>
<a name="l00384"></a>00384             is_found = <span class="keyword">true</span>;
<a name="l00385"></a>00385         }
<a name="l00386"></a>00386         cpt++;
<a name="l00387"></a>00387       }
<a name="l00388"></a>00388 
<a name="l00389"></a>00389       <span class="keywordflow">if</span>( is_found )
<a name="l00390"></a>00390       {
<a name="l00391"></a>00391         cpt--;
<a name="l00392"></a>00392         <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html" title="This class store the track of keypoints. A track is a connected set of matching keypoints across mult...">TrackOfPoints</a>&amp; track1 = (*mixed_tracks)[ cpt ];
<a name="l00393"></a>00393         <span class="keywordflow">for</span>(<span class="keywordtype">size_t</span> i=0; i&lt;track.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>.size()&amp;&amp;!is_found; ++i)
<a name="l00394"></a>00394         {<span class="comment">//check of consistency is done via addMatch...</span>
<a name="l00395"></a>00395           track1.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a83543ac9e156336f5ec070d2963f185c">addMatch</a>( track.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a3a03a4468cd94b38de2b8a9787379801" title="List of image indexes of unordered points.">images_indexes_</a>[i],
<a name="l00396"></a>00396             track.<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a245986f9cdf722e5aec386585677a188" title="List of point indexes of unordered points.">point_indexes_</a>[i] );
<a name="l00397"></a>00397         }
<a name="l00398"></a>00398       }
<a name="l00399"></a>00399       <span class="keywordflow">else</span>
<a name="l00400"></a>00400         mixed_tracks-&gt;push_back( track );
<a name="l00401"></a>00401 
<a name="l00402"></a>00402       track_it++;
<a name="l00403"></a>00403     }
<a name="l00404"></a>00404   }
<a name="l00405"></a>00405 
<a name="l00406"></a><a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a8d61827e55cee2bde8957423bc321a47">00406</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#a8d61827e55cee2bde8957423bc321a47">TrackOfPoints::keepTrackWithImages</a>( <span class="keyword">const</span>
<a name="l00407"></a>00407     std::vector&lt;int&gt;&amp; imgList,
<a name="l00408"></a>00408     std::vector&lt;TrackOfPoints&gt;&amp; tracks )
<a name="l00409"></a>00409   {
<a name="l00410"></a>00410     std::vector&lt;int&gt; cpt_Link;
<a name="l00411"></a>00411     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> cpt = 0, cpt1 = 0,
<a name="l00412"></a>00412       end = tracks.size(),
<a name="l00413"></a>00413       endImgL = imgList.size();
<a name="l00414"></a>00414     cpt_Link.assign(end,0);
<a name="l00415"></a>00415     <span class="keywordflow">for</span>(cpt = 0; cpt&lt;end; ++cpt)
<a name="l00416"></a>00416     {
<a name="l00417"></a>00417       <span class="keywordflow">for</span>(cpt1 = 0; cpt1&lt;endImgL; ++cpt1)
<a name="l00418"></a>00418       {
<a name="l00419"></a>00419         <span class="keywordflow">if</span>( tracks[cpt].<a class="code" href="class_opencv_sf_m_1_1_track_of_points.html#aea06a066b4be5fa2ff5ef09cea7fb745">containImage</a>(cpt1) )
<a name="l00420"></a>00420         {
<a name="l00421"></a>00421           cpt_Link[cpt]++;
<a name="l00422"></a>00422         }
<a name="l00423"></a>00423       }
<a name="l00424"></a>00424     }
<a name="l00425"></a>00425     <span class="comment">//remove bad tracks:</span>
<a name="l00426"></a>00426     cpt1 = 0;
<a name="l00427"></a>00427     <span class="keywordflow">for</span>(cpt = 0; cpt&lt;end-1; ++cpt)
<a name="l00428"></a>00428     {
<a name="l00429"></a>00429       <span class="keywordflow">if</span>( cpt_Link[cpt]&lt;2 )
<a name="l00430"></a>00430       {
<a name="l00431"></a>00431         tracks[cpt1] = tracks[ tracks.size()-1 ];
<a name="l00432"></a>00432         cpt1--;tracks.pop_back();
<a name="l00433"></a>00433       }
<a name="l00434"></a>00434       cpt1++;
<a name="l00435"></a>00435     }
<a name="l00436"></a>00436     <span class="comment">//last one:</span>
<a name="l00437"></a>00437     <span class="keywordflow">if</span>( cpt_Link[cpt]&lt;2 )
<a name="l00438"></a>00438       tracks.pop_back();
<a name="l00439"></a>00439   }
<a name="l00440"></a>00440 
<a name="l00441"></a><a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a96ff89db7e87560208a9bcda7f66d6bd">00441</a>   <span class="keywordtype">int</span> <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a96ff89db7e87560208a9bcda7f66d6bd">ImagesGraphConnection::getHighestLink</a>( <span class="keywordtype">int</span> &amp;first_image, <span class="keywordtype">int</span> &amp;second_image,
<a name="l00442"></a>00442     <span class="keywordtype">int</span> max_number )
<a name="l00443"></a>00443   {
<a name="l00444"></a>00444     cv::SparseMatConstIterator
<a name="l00445"></a>00445       it = <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.begin( ),
<a name="l00446"></a>00446       it_end = <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.end( );
<a name="l00447"></a>00447     <span class="keywordtype">double</span> s = 0;
<a name="l00448"></a>00448     <span class="keyword">const</span> <span class="keywordtype">int</span> dims = 2;
<a name="l00449"></a>00449     <span class="keywordtype">int</span> max_value=0;
<a name="l00450"></a>00450     <span class="keywordflow">for</span>( ; it != it_end; ++it )
<a name="l00451"></a>00451     {
<a name="l00452"></a>00452       <span class="keywordtype">int</span> currentValue=it.value&lt;<span class="keywordtype">int</span>&gt;( );
<a name="l00453"></a>00453       <span class="keywordflow">if</span>( currentValue &lt; max_number &amp;&amp; currentValue &gt; max_value )
<a name="l00454"></a>00454       {
<a name="l00455"></a>00455         max_value = currentValue;
<a name="l00456"></a>00456         <span class="keyword">const</span> cv::SparseMat::Node* n = it.node( );
<a name="l00457"></a>00457         first_image = n-&gt;idx[ 0 ];
<a name="l00458"></a>00458         second_image = n-&gt;idx[ 1 ];
<a name="l00459"></a>00459       }
<a name="l00460"></a>00460     }
<a name="l00461"></a>00461     <span class="keywordflow">return</span> max_value;
<a name="l00462"></a>00462   }
<a name="l00463"></a>00463 
<a name="l00464"></a>00464 
<a name="l00465"></a><a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a72329276aeacf384241795e3541db218">00465</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a72329276aeacf384241795e3541db218">ImagesGraphConnection::getOrderedLinks</a>( std::vector&lt;ImageLink&gt;&amp; outLinks,
<a name="l00466"></a>00466     <span class="keywordtype">int</span> min_number, <span class="keywordtype">int</span> max_number )
<a name="l00467"></a>00467   {
<a name="l00468"></a>00468     cv::SparseMatConstIterator
<a name="l00469"></a>00469       it = <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.begin( ),
<a name="l00470"></a>00470       it_end = <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.end( );
<a name="l00471"></a>00471 
<a name="l00472"></a>00472     std::vector&lt;int&gt; distance;
<a name="l00473"></a>00473     <span class="keywordtype">double</span> s = 0;
<a name="l00474"></a>00474     <span class="keyword">const</span> <span class="keywordtype">int</span> dims = 2;
<a name="l00475"></a>00475     <span class="keywordflow">for</span>( ; it != it_end; ++it )
<a name="l00476"></a>00476     {
<a name="l00477"></a>00477       <span class="keywordtype">int</span> currentValue=it.value&lt;<span class="keywordtype">int</span>&gt;( );
<a name="l00478"></a>00478       <span class="keywordflow">if</span>( currentValue &lt;= max_number &amp;&amp; currentValue &gt;= min_number )
<a name="l00479"></a>00479       {
<a name="l00480"></a>00480         <span class="keyword">const</span> cv::SparseMat::Node* n = it.node( );
<a name="l00481"></a>00481         <a class="code" href="struct_opencv_sf_m_1_1_image_link.html" title="This structure store an image link ( two image ids )...">ImageLink</a> link;
<a name="l00482"></a>00482         link.<a class="code" href="struct_opencv_sf_m_1_1_image_link.html#acf7906b02386e2a30cfb48b7b621cc35" title="index of first image">imgSrc</a> = n-&gt;idx[ 0 ];
<a name="l00483"></a>00483         link.<a class="code" href="struct_opencv_sf_m_1_1_image_link.html#ac1d76358c4e2691ed62a4cc6816f7123" title="index of second image">imgDest</a> = n-&gt;idx[ 1 ];
<a name="l00484"></a>00484         outLinks.push_back( link );
<a name="l00485"></a>00485         distance.push_back( currentValue );
<a name="l00486"></a>00486       }
<a name="l00487"></a>00487     }
<a name="l00488"></a>00488     <span class="comment">//order the list:</span>
<a name="l00489"></a>00489     quickSort( outLinks, distance, 0, distance.size( )-1 );
<a name="l00490"></a>00490   }
<a name="l00491"></a>00491 
<a name="l00492"></a><a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#aca15fc0c0206192d1c390ec4ded69e70">00492</a>   <span class="keywordtype">void</span> <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#aca15fc0c0206192d1c390ec4ded69e70">ImagesGraphConnection::getImagesRelatedTo</a>( <span class="keywordtype">int</span> first_image,
<a name="l00493"></a>00493     std::vector&lt;ImageLink&gt;&amp; outList, <span class="keywordtype">int</span> min_number, <span class="keywordtype">int</span> max_number )
<a name="l00494"></a>00494   {
<a name="l00495"></a>00495     <span class="keywordtype">int</span> it = 0,
<a name="l00496"></a>00496       it_end = <a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.size( )[ 0 ];
<a name="l00497"></a>00497     <span class="keywordflow">for</span>( ; it &lt; first_image; ++it )
<a name="l00498"></a>00498     {
<a name="l00499"></a>00499       uchar* currentValue=<a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.ptr( it, first_image, <span class="keyword">false</span> );
<a name="l00500"></a>00500       <span class="keywordflow">if</span>( currentValue != NULL )
<a name="l00501"></a>00501       {
<a name="l00502"></a>00502         <span class="comment">//we have a value here... Are there enough links:</span>
<a name="l00503"></a>00503         <span class="keywordtype">int</span> &amp;val = * <span class="keyword">reinterpret_cast&lt;</span><span class="keywordtype">int</span>*<span class="keyword">&gt;</span>( currentValue );
<a name="l00504"></a>00504         <span class="keywordflow">if</span>( val &gt; min_number &amp;&amp; val &lt; max_number )
<a name="l00505"></a>00505         {
<a name="l00506"></a>00506           <span class="comment">//it&#39;s a new link, add it:</span>
<a name="l00507"></a>00507           <a class="code" href="struct_opencv_sf_m_1_1_image_link.html" title="This structure store an image link ( two image ids )...">ImageLink</a> link;
<a name="l00508"></a>00508           link.<a class="code" href="struct_opencv_sf_m_1_1_image_link.html#acf7906b02386e2a30cfb48b7b621cc35" title="index of first image">imgSrc</a> = it;
<a name="l00509"></a>00509           link.<a class="code" href="struct_opencv_sf_m_1_1_image_link.html#ac1d76358c4e2691ed62a4cc6816f7123" title="index of second image">imgDest</a> = first_image;
<a name="l00510"></a>00510           outList.push_back( link );
<a name="l00511"></a>00511         }
<a name="l00512"></a>00512       }
<a name="l00513"></a>00513     }
<a name="l00514"></a>00514     ++it;<span class="comment">//skeep the diagonal</span>
<a name="l00515"></a>00515     <span class="keywordflow">for</span>( ; it &lt; it_end; ++it )
<a name="l00516"></a>00516     {
<a name="l00517"></a>00517       uchar* currentValue=<a class="code" href="class_opencv_sf_m_1_1_images_graph_connection.html#a20c516f5322711fe25e1b8bbcf2cc103">images_graph_</a>.ptr( first_image, it, <span class="keyword">false</span> );
<a name="l00518"></a>00518       <span class="keywordflow">if</span>( currentValue != NULL )
<a name="l00519"></a>00519       {
<a name="l00520"></a>00520         <span class="comment">//we have a value here... Are there enough links:</span>
<a name="l00521"></a>00521         <span class="keywordtype">int</span> &amp;val = * <span class="keyword">reinterpret_cast&lt;</span><span class="keywordtype">int</span>*<span class="keyword">&gt;</span>( currentValue );
<a name="l00522"></a>00522         <span class="keywordflow">if</span>( val &gt; min_number &amp;&amp; val &lt; max_number )
<a name="l00523"></a>00523         {
<a name="l00524"></a>00524           <span class="comment">//it&#39;s a new link, add it:</span>
<a name="l00525"></a>00525           <a class="code" href="struct_opencv_sf_m_1_1_image_link.html" title="This structure store an image link ( two image ids )...">ImageLink</a> link;
<a name="l00526"></a>00526           link.<a class="code" href="struct_opencv_sf_m_1_1_image_link.html#acf7906b02386e2a30cfb48b7b621cc35" title="index of first image">imgSrc</a> = first_image;
<a name="l00527"></a>00527           link.<a class="code" href="struct_opencv_sf_m_1_1_image_link.html#ac1d76358c4e2691ed62a4cc6816f7123" title="index of second image">imgDest</a> = it;
<a name="l00528"></a>00528           outList.push_back( link );
<a name="l00529"></a>00529         }
<a name="l00530"></a>00530       }
<a name="l00531"></a>00531     }
<a name="l00532"></a>00532 
<a name="l00533"></a>00533   }
<a name="l00534"></a>00534 }
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sun Aug 21 2011 16:45:52 for GSoC2011SfM by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
